<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <guanyu></guanyu>
        <zhangfei></zhangfei>
    </div>
    <script src="js/vue.js"></script>
    <script>
        var vm1 = new Vue();//两个兄弟组件之间的桥梁
        Vue.component('guanyu', {
            template: '<div>我是关羽 我三弟说：{{msg}}</div>',
            data: function() {
                return {
                    msg: ''
                }
            },
            created: function() {
                vm1.$on('myclick', (info) => {
                    this.msg = info;
                })
            }
        })
        Vue.component('zhangfei', {
            template: '<div>我是张飞 <button @click="fn">和二哥说话</button></div>',
            methods: {
                fn: function() {
                    vm1.$emit('myclick', '俺也一样')
                }
            }
        })
        var vm = new Vue({
            el: '#app',
            data: {},
            methods: {}
        });
    </script>
</body>

</html>